package cn.yejinwen.action;

import java.io.PrintWriter;
import java.util.ArrayList;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;

import org.apache.struts2.ServletActionContext;

import cn.common.tool.Head;
import cn.common.tool.JsonObject;
import cn.xiezonjie.model.Menu;
import cn.yejinwen.impl.OrderCartImpl;
import cn.yejinwen.model.Admin_id;
import cn.yejinwen.model.Carts;
import cn.yejinwen.model.Desk_id;
import cn.yejinwen.model.Menu_id;
import cn.yejinwen.model.Order;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class OrderSelectAction extends ActionSupport {

	private static final long serialVersionUID = -3351851435492476665L;
	HttpServletResponse response =  ServletActionContext.getResponse();	
	  HttpServletRequest req=ServletActionContext.getRequest();
	Menu m_id=new Menu();
	Admin_id a_id=new Admin_id();  //管理员表id
	Desk_id t_id =new Desk_id();   //餐桌表id
	
	String sele_n_name;
	ArrayList<Carts> list_selectCart;
	String select_tid;
	@SuppressWarnings("unchecked")
	/**
	 * 查询订餐车的所有内容
	 * @return
	 */
	public String selectCart()
	{   
		
		OrderCartImpl o_impl=new OrderCartImpl();	
		try
		{
		  
	        String str=req.getParameter("a");
			if(str!=null)
			{
				list_selectCart=o_impl.selectCart(0);
				select_tid="无选择任何餐桌，默认显示全部";
			}
			else
			{
				
				list_selectCart=o_impl.selectCart(Integer.parseInt(sele_n_name));
				if(Integer.parseInt(sele_n_name)==0)
				{
					select_tid="显示全部";
				}
				else
				{
					select_tid=sele_n_name;
				}
				
			}
		    return SUCCESS;
		}catch(Exception e)
		{	
			return "no";		
		}
	}

	
	/**
	 * 删除orders里的内容
	 * @return
	 */
	public String deleteCarts(){
		try{
		String m_id=req.getParameter("mid");
		String t_id_s = req.getParameter("tid");
		
		System.out.println(t_id_s+"00000000");
		t_id.setT_id(t_id_s);
	    
		
		OrderCartImpl o_impl=new OrderCartImpl();	
		@SuppressWarnings("unused")
		int str=o_impl.deleteCarts(Integer.parseInt(m_id),t_id);
		
		return "ok";
		}catch(Exception e){
			System.out.println("500"+e.getMessage());
			return "error";
		}
	}
    
	
	
		
	public Desk_id getT_id() {
		return t_id;
	}


	public void setT_id(Desk_id t_id) {
		this.t_id = t_id;
	}


	public Menu getM_id() {
		return m_id;
	}

	public void setM_id(Menu m_id) {
		this.m_id = m_id;
	}
	
	public String getSele_n_name() {
		return sele_n_name;
	}

	public void setSele_n_name(String sele_n_name) {
		this.sele_n_name = sele_n_name;
	}

	public ArrayList<Carts> getList_selectCart() {
		return list_selectCart;
	}

	public void setList_selectCart(ArrayList<Carts> list_selectCart) {
		this.list_selectCart = list_selectCart;
	}


	public String getSelect_tid() {
		return select_tid;
	}


	public void setSelect_tid(String select_tid) {
		this.select_tid = select_tid;
	}
	
	
	
	
	
	

}
